<template>
<div style="padding: 20px">
  <Button type="primary" style="margin-bottom: 10px;margin-right: 10px" @click="updateByTJSD">更新本月数据</Button>
  <Button type="success" style="margin-bottom: 10px" @click="exportData">导出数据</Button>
  <span style="color: red"> 该统计每月20号自动更新，统计不包含村</span>
  <Table ref="table" border :columns="columns" :data="data" :loading="tableLoading"></Table>
</div>
</template>

<script>
import { findAreaZhfwssTjList, updateByTJSD } from '../../api/eventlist'

export default {
  name: 'index',
  data () {
    return {
      tableLoading: false,
      columns: [
        {
          title: '序号',
          key: 'orderNo',
          align: 'center'
        },
        {
          title: '区/县',
          key: 'area_name',
          align: 'center'
        },
        {
          title: '社区数',
          key: 'sqs',
          align: 'center'
        },
        {
          title: '未达标数',
          key: 'wdbs',
          align: 'center'
        },
        {
          title: '本月达标数',
          key: 'bydbs',
          align: 'center'
        },
        {
          title: '本月达标率',
          key: 'bydbl',
          align: 'center'
        },
        {
          title: '上月未达标数',
          key: 'sywdbs',
          align: 'center'
        },
        {
          title: '上月达标数',
          key: 'sydbs',
          align: 'center'
        },
        {
          title: '上月达标率',
          key: 'sydbl',
          align: 'center'
        },
        {
          title: '达标率增幅',
          key: 'dblzf',
          align: 'center'
        },
        {
          title: '本月达标率排名',
          key: 'dblpm',
          align: 'center'
        },
        {
          title: '增幅排名',
          key: 'dblzfpm',
          align: 'center'
        }
      ],
      data: []
    }
  },
  methods: {
    init () {
      this.tableLoading = true
      findAreaZhfwssTjList().then(ret => {
        if (ret.data.errcode === 0) {
          this.data = ret.data.data
          this.tableLoading = false
        } else {
          this.$Notice.error({ title: '查询失败！', desc: ret.data.errmsg })
        }
      })
    },
    updateByTJSD () {
      updateByTJSD().then(ret => {
        if (ret.data.errcode === 0) {
          this.data = ret.data.data
          this.init()
        } else {
          this.$Notice.error({ title: '更新失败！', desc: ret.data.errmsg })
        }
      })
    },
    exportData () {
      let d = new Date() // 不指定日期          默认返回“格林尼治”零时区日期
      let year = d.getFullYear() // 返回当前年份        2022    2022年
      let month = d.getMonth() + 1
      this.$refs.table.exportCsv({
        filename: '综合服务设施统计' + year + '_' + month,
        columns: this.columns,
        data: this.data
      })
    }
  },
  mounted () {
    this.init()
  }
}
</script>

<style scoped>

</style>
